package com.estore.model;

import java.io.Serializable;

public class Product implements Comparable<Product>, Serializable {
    private static final long serialVersionUID = 1L;
    private String id;
    private String name;
    private double price;
    private int stock;

    public Product(String id, String name, double price, int stock) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
    }
    public String getId() { return id; }
    public String getName() { return name; }
    public double getPrice() { return price; }
    public int getStock() { return stock; }
    public void setId(String id) { this.id = id; }
    public void setName(String name) { this.name = name; }
    public void setPrice(double price) { this.price = price; }
    public void setStock(int stock) { this.stock = stock; }
    public String toString() {
        return String.format("ID: %s, 名称: %s, 价格: %.2f, 库存: %d",
                id, name, price, stock);
    }
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return id.equals(product.id);
    }
    public int hashCode() { return id.hashCode(); }
    public int compareTo(Product other) {
        return this.id.compareTo(other.id); // 按ID排序
    }
}